# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=libyaml

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.1.4
pkgrel=2
pkgdesc="YAML 1.1 library (mingw-w64)"
arch=('any')
url="http://pyyaml.org/wiki/LibYAML"
license=("MIT")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-pkg-config")
options=('staticlibs' 'strip')
source=("http://pyyaml.org/download/libyaml/yaml-$pkgver.tar.gz"
"0001-Proper-mingw-YAML_DECLARE-definition.patch")
md5sums=('36c852831d02cf90508c29852361d01b'
         '62993ee836b420adc99bc42dff09436b')

prepare() {
    cd "$srcdir/yaml-$pkgver"
    patch -Np1 -i "$srcdir/0001-Proper-mingw-YAML_DECLARE-definition.patch"
}

build() {
    mkdir -p "${srcdir}/${_realname}-${pkgver}-build-${CARCH}"
    cd "${srcdir}/${_realname}-${pkgver}-build-${CARCH}"
    "${srcdir}"/yaml-$pkgver/configure \
      --prefix=${MINGW_PREFIX} \
      --build=${MINGW_CHOST} \
      --host=${MINGW_CHOST} \
      --target=${MINGW_CHOST}
    make
    gcc -shared src/.libs/*.o -o libyaml.dll -Xlinker --out-implib -Xlinker libyaml.dll.a
}

package() {
    cd "${srcdir}/${_realname}-${pkgver}-build-${CARCH}"
    make DESTDIR="$pkgdir" install
    install -Dm644 "libyaml.dll" "${pkgdir}${MINGW_PREFIX}/bin/libyaml.dll"
    install -m644 "libyaml.dll.a" "${pkgdir}${MINGW_PREFIX}/lib/libyaml.dll.a"
}
